package com.kurumi.util;

import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;



/**
 * ExcelUtil
 * @author lyh
 *
 */
public class ExcelUtil {

	/**
	 * 导出excel数据
	 *
	 * @param filePath
	 * @return
	 */
	public static void exportExcel(OutputStream out, String[] headers, List<Map<String, Object>> mapList) {
		// 创建一个工作薄
		try {
			XSSFWorkbook workbook = new XSSFWorkbook();
			XSSFSheet sheet = workbook.createSheet();
			XSSFRow row = null;
			XSSFCell cell =null;
			//SXSSFCell cell =null;
			// 创建一个工作薄
			//SXSSFWorkbook workbook = new SXSSFWorkbook();
			// 创建一个sheet页
			//SXSSFSheet sheet = workbook.createSheet();
			// 设置sheet页的列宽
			//sheet.setDefaultColumnWidth(20);

			// 设置标题样式
			//CellStyle titleStyle = workbook.createCellStyle();
			// 设置字体居中显示
		//	titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			// 设置标题字体
			//XSSFFont titleFont = workbook.createFont();
			//titleFont.setFontHeightInPoints((short) 25);
		//	titleStyle.setFont(titleFont);

			// 产生标题
			//SXSSFRow row = null;
			//SXSSFCell cell =null;
			//cell.setCellStyle(titleStyle);
		//	cell.setCellValue(title);
			// 合并单元格
			//sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, header.length - 1));

			// 表头样式
			//XSSFCellStyle headStyle = workbook.createCellStyle();
			//headStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
			// 设置填充模式
			//headStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

			// 设置字体居中
			//headStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			//headStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			//headStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			//headStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
			//headStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
			// 设置字体样式
			//Font headFont = workbook.createFont();
			//headFont.setColor(HSSFColor.LIGHT_ORANGE.index);
			//headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 设置字体粗细
			//headFont.setFontHeightInPoints((short) 16);
			//headStyle.setFont(headFont);
			// 创建第二行，生成表格的表头行
			row = sheet.createRow(0);// 第二行
			for (int i = 0; i < headers.length; i++) {
				cell = row.createCell(i);// 从第一列开始
				//cell.setCellStyle(headStyle);// 设置列的样式
				cell.setCellValue(headers[i]);
			}
			int i = 0;
			for (Map<String, Object> cellMap : mapList) {
				row = sheet.createRow(1 + i);// 从第三行去写数据
				for(int colIndex = 0; colIndex < headers.length; colIndex++){
					cell = row.createCell(colIndex);
					Object value = cellMap.get(headers[colIndex]);
					if(value!=null){
						if(value instanceof Date){
							cell.setCellValue((Date)value);
						}else if(value instanceof Integer){
							cell.setCellValue((Integer)value);
						}else if(value instanceof BigDecimal
								|| value instanceof Float
								|| value instanceof Double){
							cell.setCellValue(ObjectUtils.getDoubleValue(value));
						}else{
							cell.setCellValue(ObjectUtils.getStringValue(value));
						}
					}
				}

				i++;
			}

			workbook.write(out);
			out.flush();
			out.close();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}




	public static void exportExcel(OutputStream out, String title,String[] headers,List<String> keys, List<Map<String, Object>> datas) {

		try {

			// 创建一个工作薄
			HSSFWorkbook workbook = new HSSFWorkbook();
			// 创建一个sheet页
			HSSFSheet sheet = workbook.createSheet();
			// 设置sheet页的列宽
			sheet.setDefaultColumnWidth(20);

			// 设置标题样式
			HSSFCellStyle titleStyle = workbook.createCellStyle();
			// 设置字体居中显示
			//titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			// 设置标题字体
			HSSFFont titleFont = workbook.createFont();
			titleFont.setFontHeightInPoints((short) 25);
			titleStyle.setFont(titleFont);

			// 产生标题
			HSSFRow row = sheet.createRow(0);
			HSSFCell cell = row.createCell(0);
			cell.setCellStyle(titleStyle);
			cell.setCellValue(title);
			// 合并单元格
			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headers.length - 1));

			// 表头样式
			HSSFCellStyle headStyle = workbook.createCellStyle();
			//headStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
			// 设置填充模式
			//headStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

			// 设置字体居中
			//headStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			//headStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			//headStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			//headStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
			//headStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
			// 设置字体样式
			HSSFFont headFont = workbook.createFont();
			//headFont.setColor(HSSFColor.LIGHT_ORANGE.index);
			//headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 设置字体粗细
			headFont.setFontHeightInPoints((short) 16);
			headStyle.setFont(headFont);
			// 创建第二行，生成表格的表头行
			row = sheet.createRow(1);// 第二行
			for (int i = 0; i < headers.length; i++) {
				cell = row.createCell(i);// 从第一列开始
				cell.setCellStyle(headStyle);// 设置列的样式
				cell.setCellValue(headers[i]);
			}
			int i = 0;
			for (Map<String, Object> data : datas) {
				row = sheet.createRow(2 + i);// 从第三行去写数据

				for(int colIndex = 0; colIndex < keys.size(); colIndex++){
					cell = row.createCell(colIndex);
					Object value = data.get(keys.get(colIndex));
					ExcelUtils.setCellValue(cell, value);
				}
				i++;
			}

			workbook.write(out);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static void exportExcelOfPageIndex(OutputStream out,List<Map<String, Object>> datas) {

		try {

			// 创建一个工作薄
			XSSFWorkbook workbook = new XSSFWorkbook();
			// 创建一个sheet页
			XSSFSheet sheet = workbook.createSheet();

			XSSFRow row = null;
			XSSFCell cell = null;

			// 创建第一行，生成表格的表头行
			row = sheet.createRow(0);// 第一行
			/*String[] headers =
				{"P900","P6891","P686","P800",
				"P1","P2","P3","P4",
				"P5","P6","P7","P8",
				"P9","P101","P102","P103",
				"P11","P12","P13","P801",
				"P802","P803","P14","P15",
				"P16","P17","P171","P18",
				"P19","P20","P804","P21",
				"P22","P23","P231","P24",
				"P25","P26","P261","P27",
				"P28","P281","P29","P30",
				"P301","P31","P321","P322",
				"P805","P323","P324","P325",
				"P806","P326","P327","P328",
				"P807","P329","P3291","P3292",
				"P808","P3293","P3294","P3295",
				"P809","P3296","P3297","P3298",
				"P810","P3299","P3281","P3282",
				"P811","P3283","P3284","P3285",
				"P812","P3286","P3287","P3288",
				"P813","P3289","P3271","P3272",
				"P814","P3273","P3274","P3275",
				"P815","P3276","P689","P351",
				"P352","P816","P353","P354",
				"P817","P355","P356","P818",
				"P361","P362","P363","P364",
				"P365","P366","P371","P372",
				"P38","P39","P40","P411",
				"P412","P413","P414","P415",
				"P421","P422","P687","P688",
				"P431","P432","P433","P434",
				"P819","P435","P436","P437",
				"P438","P44","P45","P46",
				"P47","P490","P491","P820",
				"P492","P493","P494","P495",
				"P496","P497","P498","P4981",
				"P499","P4910","P4911","P4912",
				"P821","P4913","P4914","P4915",
				"P4916","P4917","P4918","P4919",
				"P4982","P4920","P4921","P4922",
				"P4923","P822","P4924","P4925",
				"P4526","P4527","P4528","P4529",
				"P4530","P4983","P4531","P4532",
				"P4533","P4534","P823","P4535",
				"P4536","P4537","P4538","P4539",
				"P4540","P4541","P4984","P4542",
				"P4543","P4544","P4545","P824",
				"P4546","P4547","P4548","P4549",
				"P4550","P4551","P4552","P4985",
				"P4553","P4554","P45002","P45003",
				"P825","p45004","p45005","p45006",
				"p45007","p45008","p45009","p45010",
				"p45011","p45012","p45013","p45014",
				"p45015","P826","p45016","p45017",
				"p45018","p45019","p45020","p45021",
				"p45022","p45023","p45024","p45025",
				"p45026","p45027","P827","p45028",
				"p45029","p45030","p45031","p45032",
				"p45033","p45034","p45035","p45036",
				"p45037","p45038","p45039","P828",
				"p45040","p45041","p45042","p45043",
				"p45044","p45045","p45046","p45047",
				"p45048","p45049","p45050","p45051",
				"P829","p45052","p45053","p45054",
				"p45055","p45056","p45057","p45058",
				"p45059","p45060","p45061","P561",
				"P562","P563","P564","P6911",
				"P6912","P6913","P6914","P6915",
				"P6916","P6917","P6918","P6919",
				"P6920","P6921","P6922","P6923",
				"P6924","P6925","P57","P58",
				"P581","P60","P611","P612",
				"P613","P59","P62","P63",
				"P64","P651","P652","P653",
				"P654","P655","P656","P66",
				"P681","P682","P683","P684",
				"P685","P67","P731","P732",
				"P733","P734","P72","P830",
				"P831","P741","P742","P743",
				"P782","P751","P752","P754",
				"P755","P756","P757","P758",
				"P759","P760","P761","P762",
				"P763","P764","P765","P767",
				"P768","P769","P770","P771",
				"P772","P773","P774","P775",
				"P776","P777","P778","P779",
				"P780","P781"};*/
			/*String[] headers1 =
				{ "医疗机构代码","机构名称","医疗保险手册（卡）号","健康卡号",
				"医疗付款方式","住院次数","病案号","姓名",
				"性别","出生日期","年龄","婚姻状况",
				"职业","出生省份","出生地市","出生地县",
				"民族","国籍","身份证号","现住址",
				"住宅电话","现住址邮政编码","工作单位及地址","电话",
				"工作单位邮政编码","户口地址","户口所在地邮政编码","联系人姓名",
				"关系","联系人地址","入院途径","联系人电话",
				"入院日期","入院科别","入院病室","转科科别",
				"出院日期","出院科别","出院病室","实际住院天数",
				"门（急）诊诊断编码","门（急）诊诊断描述","入院时情况","入院诊断编码",
				"入院诊断描述","入院后确诊日期","主要诊断编码","主要诊断疾病描述",
				"主要诊断入院病情","主要诊断出院情况","其他诊断编码1","其他诊断疾病描述1",
				"其他诊断入院病情1","其他诊断出院情况1","其他诊断编码2","其他诊断疾病描述2",
				"其他诊断入院病情2","其他诊断出院情况2","其他诊断编码3","其他诊断疾病描述3",
				"其他诊断入院病情3","其他诊断出院情况3","其他诊断编码4","其他诊断疾病描述4",
				"其他诊断入院病情4","其他诊断出院情况4","其他诊断编码5","其他诊断疾病描述5",
				"其他诊断入院病情5","其他诊断出院情况5","其他诊断编码6","其他诊断疾病描述6",
				"其他诊断入院病情6","其他诊断出院情况6","其他诊断编码7","其他诊断疾病描述7",
				"其他诊断入院病情7","其他诊断出院情况7","其他诊断编码8","其他诊断疾病描述8",
				"其他诊断入院病情8","其他诊断出院情况8","其他诊断编码9","其他诊断疾病描述9",
				"其他诊断入院病情9","其他诊断出院情况9","其他诊断编码10","其他诊断疾病描述10",
				"其他诊断入院病情10","其他诊断出院情况10","医院感染总次数","病理诊断编码1",
				"病理诊断名称1","病理号1","病理诊断编码2","病理诊断名称2",
				"病理号2","病理诊断编码3","病理诊断名称3","病理号3",
				"损伤、中毒的外部因素编码1","损伤、中毒的外部因素名称1","损伤、中毒的外部因素编码2","损伤、中毒的外部因素名称2",
				"损伤、中毒的外部因素编码3","损伤、中毒的外部因素名称3","过敏源","过敏药物名称",
				"HBsAg","HCV-Ab","HIV-Ab","门诊与出院诊断符合情况",
				"入院与出院诊断符合情况","术前与术后诊断符合情况","临床与病理诊断符合情况","放射与病理诊断符合情况",
				"抢救次数","抢救成功次数","最高诊断依据","分化程度",
				"科主任","主(副主)任医师","主治医师","住院医师",
				"责任护士","进修医师","研究生实习医师","实习医师",
				"编码员","病案质量","质控医师","质控护师",
				"质控日期","手术操作编码1","手术操作日期1","手术级别1",
				"手术操作名称1","手术操作部位1","手术持续时间1","术者1",
				"Ⅰ助1","Ⅱ助1","麻醉方式1","麻醉分级1",
				"切口愈合等级1","麻醉医师1","手术操作编码2","手术操作日期2",
				"手术级别2","手术操作名称2","手术操作部位2","手术持续时间2",
				"术者2","Ⅰ助2","Ⅱ助2","麻醉方式2",
				"麻醉分级2","切口愈合等级2","麻醉医师2","手术操作编码3",
				"手术操作日期3","手术级别3","手术操作名称3","手术操作部位3",
				"手术持续时间3","术者3","Ⅰ助3","Ⅱ助3",
				"麻醉方式3","麻醉分级3","切口愈合等级3","麻醉医师3",
				"手术操作编码4","手术操作日期4","手术级别4","手术操作名称4",
				"手术操作部位4","手术持续时间4","术者4","Ⅰ助4",
				"Ⅱ助4","麻醉方式4","麻醉分级4","切口愈合等级4",
				"麻醉医师4","手术操作编码5","手术操作日期5","手术级别5",
				"手术操作名称5","手术操作部位5","手术持续时间5","术者5",
				"Ⅰ助5","Ⅱ助5","麻醉方式5","麻醉分级5",
				"切口愈合等级5","麻醉医师5","手术操作编码6","手术操作日期6",
				"手术级别6","手术操作名称6","手术操作部位6","手术持续时间6",
				"术者6","Ⅰ助6","Ⅱ助6","麻醉方式6",
				"麻醉分级6","切口愈合等级6","麻醉医师6","手术操作编码7",
				"手术操作日期7","手术级别7","手术操作名称7","手术操作部位7",
				"手术持续时间7","术者7","Ⅰ助7","Ⅱ助7",
				"麻醉方式7","麻醉分级7","切口愈合等级7","麻醉医师7",
				"手术操作编码8","手术操作日期8","手术级别8","手术操作名称8",
				"手术操作部位8","手术持续时间8","术者8","Ⅰ助8",
				"Ⅱ助8","麻醉方式8","麻醉分级8","切口愈合等级8",
				"麻醉医师8","手术操作编码9","手术操作日期9","手术级别9",
				"手术操作名称9","手术操作部位9","手术持续时间9","术者9",
				"Ⅰ助9","Ⅱ助9","麻醉方式9","麻醉分级9",
				"切口愈合等级9","麻醉医师9","手术操作编码10","手术操作日期10",
				"手术级别10","手术操作名称10","手术操作部位10","手术持续时间10",
				"术者10","Ⅰ助10","Ⅱ助10","麻醉方式10",
				"麻醉分级10","切口愈合等级10","麻醉医师10","特级护理天数",
				"一级护理天数","二级护理天数","三级护理天数","重症监护室名称1",
				"进入时间1","退出时间1","重症监护室名称2","进入时间2",
				"退出时间2","重症监护室名称3","进入时间3","退出时间3",
				"重症监护室名称4","进入时间4","退出时间4","重症监护室名称5",
				"进入时间5","退出时间5","死亡患者尸检","手术、治疗、检查、诊",
				"断为本院第一例","手术患者类型","随诊","随诊周数",
				"随诊月数","随诊年数","示教病例","ABO血型",
				"Rh血型","输血反应","红细胞","血小板",
				"血浆","全血","自体回收","其它",
				"（婴幼儿）年龄","新生儿出生体重1","新生儿出生体重2","新生儿出生体重3",
				"新生儿出生体重4","新生儿出生体重5","新生儿入院体重","入院前多少小时(颅脑损伤患者昏迷时间)",
				"入院前多少分钟(颅脑损伤患者昏迷时间)","入院后多少小时(颅脑损伤患者昏迷时间)","入院后多少分钟(颅脑损伤患者昏迷时间)","呼吸机使用时间",
				"是否有出院31天内再住院计划","出院31天再住院计划目的","转入医院名称","转入社区服务机构/乡镇卫生院名称",
				"住院总费用","住院总费用其中自付金额","一般医疗服务费","一般治疗操作费",
				"护理费","综合医疗服务类其他费用","病理诊断费","实验室诊断费",
				"影像学诊断费","临床诊断项目费","非手术治疗项目费","临床物理治疗费",
				"手术治疗费","麻醉费","手术费","康复费",
				"中医治疗费","西药费","抗菌药物费用","中成药费",
				"中草药费","血费","白蛋白类制品费","球蛋白类制品费",
				"凝血因子类制品费","细胞因子类制品费","检查用一次性医用材料费","治疗用一次性医用材料费",
				"手术用一次性医用材料费","其他费"};*/

			String[] headers =
				{"USERNAME","YLFKFS","JKKH","ZYCS"
				,"BAH","XM","XB","CSRQ(YYYYMMDD)"
				,"NL","GJ","BZYZSNL","XSECSTZ"
				,"XSERYTZ","CSD_SG","CSD_SI","CSD_QX"
				,"CSD_DZ","GG_SG","GG_SI","MZ"
				,"SFZJLB","SFZH","ZY","HY"
				,"XZZ_SG","XZZ_SI","XZZ_QX","XZZ_DZ"
				,"DH","YB1","HKDZ_SG","HKDZ_SI"
				,"HKDZ_QX","HKDZ_DZ","YB2","GZDWJDZMC",
				"GZDWJDZ_SG","GZDWJDZ_SI","GZDWJDZ_QX","GZDWJDZ_DZ"
				,"DWDH","YB3","LXRXM","GX"
				,"DZ_SG","DZ_SI","DZ_QX","DZ_DZ"
				,"DH2","RYTJ","ZZYLJGMC","RYSJ"
				,"RYSJS","RYKB","RYBF","ZKKB"
				,"ZKKB1","ZKKB2","CYSJ","CYSJS"
				,"CYKB","CYBF","SJZYTS","MZZD"
				,"JBBM","ZYZD","JBDM","RYBQ"
				,"QTZD1","JBDM1","RYBQ1","QTZD2","JBDM2","RYBQ2","QTZD3","JBDM3","RYBQ3"
				,"QTZD4","JBDM4","RYBQ4","QTZD5","JBDM5","RYBQ5","QTZD6","JBDM6","RYBQ6"
				,"QTZD7","JBDM7","RYBQ7","QTZD8","JBDM8","RYBQ8","QTZD9","JBDM9","RYBQ9"
				,"QTZD10","JBDM10","RYBQ10","QTZD11","JBDM11","RYBQ11","QTZD12","JBDM12","RYBQ12"
				,"QTZD13","JBDM13","RYBQ13","QTZD14","JBDM14","RYBQ14","QTZD15","JBDM15","RYBQ15"
				,"WBYY","H23","BLZD","JBMM","BLH"
				,"ICDO3","ZGZDYJ","YWGM","GMYW"
				,"SWHZSJ","XX","TJHL_T","YJHL_T","EJHL_T","SJHL_T"
				,"RH","KZR","YLZZ","ZRYS","ZZYS","ZYYS"
				,"ZRHS","JXYS","SXYS","BMY","BAZL","ZKYS","ZKHS","ZKRQ"
				,"SSJCZBM1","SSJCZRQ1","SSJB1","SSLX1","SSJCZMC1","SZ1","YZ1","EZ1"
				,"QKDJ1","QKYHLB1","MZFS1","MZYS1"
				,"SSJCZBM2","SSJCZRQ2","SSJB2","SSLX2","SSJCZMC2","SZ2","YZ2","EZ2"
				,"QKDJ2","QKYHLB2","MZFS2","MZYS2"
				,"SSJCZBM3","SSJCZRQ3","SSJB3","SSLX3","SSJCZMC3","SZ3","YZ3","EZ3"
				,"QKDJ3","QKYHLB3","MZFS3","MZYS3"
				,"SSJCZBM4","SSJCZRQ4","SSJB4","SSLX4","SSJCZMC4","SZ4","YZ4","EZ4"
				,"QKDJ4","QKYHLB4","MZFS4","MZYS4"
				,"SSJCZBM5","SSJCZRQ5","SSJB5","SSLX5","SSJCZMC5","SZ5","YZ5","EZ5"
				,"QKDJ5","QKYHLB5","MZFS5","MZYS5"
				,"SSJCZBM6","SSJCZRQ6","SSJB6","SSLX6","SSJCZMC6","SZ6","YZ6","EZ6"
				,"QKDJ6","QKYHLB6","MZFS6","MZYS6"
				,"SSJCZBM7","SSJCZRQ7","SSJB7","SSLX7","SSJCZMC7","SZ7","YZ7","EZ7"
				,"QKDJ7","QKYHLB7","MZFS7","MZYS7"
				,"SSJCZBM8","SSJCZRQ8","SSJB8","SSLX8","SSJCZMC8","SZ8","YZ8","EZ8"
				,"QKDJ8","QKYHLB8","MZFS8","MZYS8"
				,"RJQK","WCQK","BYQK","LYFS","YZZY_YLJG"
				,"WSY_YLJG","SFZZYJH","MD"
				,"RYQ_T","RYQ_XS","RYQ_F"
				,"RYH_T","RYH_XS","RYH_F"};
			String[] headers1 =
				{ "机构名称","医疗付款方式(代码)","健康卡号","住院次数"
				,"病案号","姓名","性别(代码)","出生日期(YYYYMMDD)"
				,"年龄(岁)","国籍(代码)","(年龄不足1周岁的)年龄(月)","新生儿出生体重(克)"
				,"新生儿入院体重(克）","出生地_省(代码)","出生地—市(代码)","出生地—区县(代码)"
				,"出生地—详细地址","籍贯—省(代码)","籍贯—市(代码)","民族(代码)"
				,"身份证件类别(代码)","身份证号","职业(代码)","婚姻(代码)"
				,"现住址—省(代码)","现住址—市(代码)","现住址—区县(代码)","现住址—详细地址"
				,"电话","邮编","户口地址—省(代码)","户口地址—市(代码)"
				,"户口地址—区县(代码)","户口地址—详细地址","邮编","工作单位名称"
				,"工作单位及地址—省(代码)","工作单位及地址—市(代码)","工作单位及地址—区县(代码)","工作单位及地址—详细地址"
				,"单位电话","单位邮编","联系人姓名","联系人关系(代码)"
				,"联系人地址—省(代码)","联系人地址—市(代码)","联系人地址—区县(代码)","联系人地址—详细地址"
				,"联系人电话","入院途径(代码)","转诊医疗机构名称","入院时间(YYYYMMDD)"
				,"入院时间(HH:时)","入院科别(代码)","入院病房","转科科别(代码)"
				,"转科科别1(代码)","转科科别2(代码)","出院时间(YYYYMMDD)","出院时间(HH:时)"
				,"出院科别(代码)","出院病房","实际住院(天)","门(急)诊诊断疾病描述"
				,"门(急)诊诊断疾病编码","主要诊断疾病描述","主要诊断疾病编码","主要诊断入院病情(代码)"
				,"其他诊断1疾病描述","其他诊断1疾病编码","其他诊断1入院病情(代码)","其他诊断2疾病描述","其他诊断2疾病编码","其他诊断2入院病情(代码)","其他诊断3疾病描述","其他诊断3疾病编码","其他诊断3入院病情(代码)"
				,"其他诊断4疾病描述","其他诊断4疾病编码","其他诊断4入院病情(代码)","其他诊断5疾病描述","其他诊断5疾病编码","其他诊断5入院病情(代码)","其他诊断6疾病描述","其他诊断6疾病编码","其他诊断6入院病情(代码)"
				,"其他诊断7疾病描述","其他诊断7疾病编码","其他诊断7入院病情(代码)","其他诊断8疾病描述","其他诊断8疾病编码","其他诊断8入院病情(代码)","其他诊断9疾病描述","其他诊断9疾病编码","其他诊断9入院病情(代码)"
				,"其他诊断10疾病描述","其他诊断10疾病编码","其他诊断10入院病情(代码)","其他诊断11疾病描述","其他诊断11疾病编码","其他诊断11入院病情(代码)","其他诊断12疾病描述","其他诊断12疾病编码","其他诊断12入院病情(代码)"
				,"其他诊断13疾病描述","其他诊断13疾病编码","其他诊断13入院病情(代码)","其他诊断14疾病描述","其他诊断14疾病编码","其他诊断14入院病情(代码)","其他诊断15疾病描述","其他诊断15疾病编码","其他诊断15入院病情(代码)"
				,"中毒的外部原因疾病描述","中毒的外部原因疾病编码","病理诊断疾病描述","病理诊断疾病编码","病理号"
				,"ICD-O-3","最高诊断依据(代码)","药物过敏","过敏药物疾病"
				,"死亡患者尸检(代码)","血型(代码)","特级护理","Ⅰ级护理(天)","Ⅱ级护理(天)","Ⅲ级护理(天)"
				,"Rh(代码)","科主任","医疗组长","主任（副主任）医师","主治医师","住院医师"
				,"责任护士","进修医师","实习医师","编码员","病案质量(代码)","质控医师","质控护士","质控日期(YYYYMMDD)"
				,"手术及操作编码1","手术及操作日期(YYYYMMDD)1","手术级别(代码)1","手术类型1","手术及操作名称1","术者1","I助1","II助1"
				,"切口等级(代码)1","切口愈合类别(代码)1","麻醉方式(代码)1","麻醉医师1"
				,"手术及操作编码2","手术及操作日期(YYYYMMDD)2","手术级别(代码)2","手术类型2","手术及操作名称2","术者2","I助2","II助2"
				,"切口等级(代码)2","切口愈合类别(代码)2","麻醉方式(代码)2","麻醉医师2"
				,"手术及操作编码3","手术及操作日期(YYYYMMDD)3","手术级别(代码)3","手术类型3","手术及操作名称3","术者3","I助3","II助3"
				,"切口等级(代码)3","切口愈合类别(代码)3","麻醉方式(代码)3","麻醉医师3"
				,"手术及操作编码4","手术及操作日期(YYYYMMDD)4","手术级别(代码)4","手术类型4","手术及操作名称4","术者4","I助4","II助4"
				,"切口等级(代码)4","切口愈合类别(代码)4","麻醉方式(代码)4","麻醉医师4"
				,"手术及操作编码5","手术及操作日期(YYYYMMDD)5","手术级别(代码)5","手术类型5","手术及操作名称5","术者5","I助5","II助5"
				,"切口等级(代码)5","切口愈合类别(代码)5","麻醉方式(代码)5","麻醉医师5"
				,"手术及操作编码6","手术及操作日期(YYYYMMDD)6","手术级别(代码)6","手术类型6","手术及操作名称6","术者6","I助6","II助6"
				,"切口等级(代码)6","切口愈合类别(代码)6","麻醉方式(代码)6","麻醉医师6"
				,"手术及操作编码7","手术及操作日期(YYYYMMDD)7","手术级别(代码)7","手术类型7","手术及操作名称7","术者7","I助7","II助7"
				,"切口等级(代码)7","切口愈合类别(代码)7","麻醉方式(代码)7","麻醉医师7"
				,"手术及操作编码8","手术及操作日期(YYYYMMDD)8","手术级别(代码)8","手术类型8","手术及操作名称8","术者8","I助8","II助8"
				,"切口等级(代码)8","切口愈合类别(代码)8","麻醉方式(代码)8","麻醉医师8"
				,"入径情况(代码)","完成情况(代码)","变异情况(代码)","离院方式(代码)","医嘱转院，拟接收医疗机构名称"
				,"医嘱转社区卫生服务机构/乡镇卫生院，拟接收医疗机构名称","是否有出院31天内再住院计划手术情况(代码)","目的"
				,"颅脑损伤患者昏迷入院前时间：天","颅脑损伤患者昏迷入院前时间：小时","颅脑损伤患者昏迷入院前时间：分"
				,"颅脑损伤患者昏迷入院后时间：天","颅脑损伤患者昏迷入院后时间：小时","颅脑损伤患者昏迷入院后时间：分"};
			for (int i = 0; i < headers.length; i++) {
				cell = row.createCell(i);// 从第一列开始
				cell.setCellValue(headers[i]);
			}
			int i = 0;
			for (Map<String, Object> data : datas) {
				Map<String, Object> jsonMap = (Map<String, Object>)data.get("jsonMap");
				row = sheet.createRow(1 + i);// 从第二行去写数据
				if(jsonMap != null){
					Map<String, Object> basicInfo = (Map<String, Object>)jsonMap.get("basicInfo");
					Map<String, Object> cureInfo = (Map<String, Object>)jsonMap.get("cureInfo");
					//[start] 1-20
					int colIndex = 0;
					//1
					cell = row.createCell(colIndex);
					setCellValue("XX医院",cell);
					colIndex ++;
					//2
					cell = row.createCell(colIndex);
					Object medicalPayTypeCode = basicInfo.get("medicalPayTypeCode");
					setCellValue(medicalPayTypeCode,cell);
					colIndex ++;
					//3
					cell = row.createCell(colIndex);
					Object medicalHealthNumber = basicInfo.get("medicalHealthNumber");
					setCellValue(medicalHealthNumber,cell);
					colIndex ++;
					//4
					cell = row.createCell(colIndex);
					Object visitNumber = basicInfo.get("visitNumber");
					setCellValue(visitNumber,cell);
					colIndex ++;
					//5
					cell = row.createCell(colIndex);
					Object mrId = basicInfo.get("mrId");
					setCellValue(mrId,cell);
					//6
					colIndex ++;
					cell = row.createCell(colIndex);
					Object patientName = basicInfo.get("patientName");
					setCellValue(patientName,cell);
					//7
					colIndex ++;
					cell = row.createCell(colIndex);
					Object sexCode = basicInfo.get("sexCode");
					setCellValue(sexCode,cell);
					//8
					colIndex ++;
					cell = row.createCell(colIndex);
					Object birthday = basicInfo.get("birthday");
					if(birthday != null){
						cell.setCellValue(((String)birthday).replaceAll("-", ""));
					}
					//9
					colIndex ++;
					cell = row.createCell(colIndex);
					Object yearOfAge = basicInfo.get("yearOfAge");
					setCellValue(yearOfAge,cell);
					//10
					colIndex ++;
					cell = row.createCell(colIndex);
					Object nationalityCode = basicInfo.get("nationalityCode");
					setCellValue(nationalityCode,cell);
					//11
					colIndex ++;
					cell = row.createCell(colIndex);
					Object monthOfAge = basicInfo.get("monthOfAge");
					setCellValue(monthOfAge,cell);
					//12
					colIndex ++;
					cell = row.createCell(colIndex);
					if(cureInfo != null){
						Object babyBirthWeight = cureInfo.get("babyBirthWeight");
						setCellValue(babyBirthWeight,cell);
					}
					//13
					colIndex ++;
					cell = row.createCell(colIndex);
					if(cureInfo != null){
						Object babyInHospitalWeight = cureInfo.get("babyInHospitalWeight");
						setCellValue(babyInHospitalWeight,cell);
					}
					Map<String, Object> birthRegionalism =(Map<String, Object>)basicInfo.get("birthRegionalism");
					//14
					colIndex ++;
					cell = row.createCell(colIndex);
					if(birthRegionalism != null){
						Object provinceCode = birthRegionalism.get("provinceCode");
						setCellValue(provinceCode,cell);
					}
					//15
					colIndex ++;
					cell = row.createCell(colIndex);
					if(birthRegionalism != null){
						Object cityCode = birthRegionalism.get("cityCode");
						setCellValue(cityCode,cell);
					}
					//16
					colIndex ++;
					cell = row.createCell(colIndex);
					if(birthRegionalism != null){
						Object countyCode = birthRegionalism.get("countyCode");
						setCellValue(countyCode,cell);
					}

					//17
					colIndex ++;
					cell = row.createCell(colIndex);
					Object birthAddress = basicInfo.get("birthAddress");
					setCellValue(birthAddress,cell);

					Map<String, Object> nativePlaceRegionalism =(Map<String, Object>)basicInfo.get("nativePlaceRegionalism");

					//18
					colIndex ++;
					cell = row.createCell(colIndex);
					if(nativePlaceRegionalism != null){
						Object provinceCode = nativePlaceRegionalism.get("provinceCode");
						setCellValue(provinceCode,cell);
					}

					//19
					colIndex ++;
					cell = row.createCell(colIndex);
					if(nativePlaceRegionalism != null){
						Object cityCode = nativePlaceRegionalism.get("cityCode");
						setCellValue(cityCode,cell);
					}

					//20
					colIndex ++;
					cell = row.createCell(colIndex);
					Object nationCode = basicInfo.get("nationCode");
					setCellValue(nationCode,cell);
					//[end]

					//[start] 21-40
					//21
					colIndex ++;
					cell = row.createCell(colIndex);
					Object documentTypeCode = basicInfo.get("documentTypeCode");
					setCellValue(documentTypeCode,cell);

					//22
					colIndex ++;
					cell = row.createCell(colIndex);
					Object idNumber = basicInfo.get("idNumber");
					setCellValue(idNumber,cell);

					//23
					colIndex ++;
					cell = row.createCell(colIndex);
					Object professionCode = basicInfo.get("professionCode");
					setCellValue(professionCode,cell);

					//24
					colIndex ++;
					cell = row.createCell(colIndex);
					Object marriageCode = basicInfo.get("marriageCode");
					setCellValue(marriageCode,cell);

					Map<String, Object> permanentAddressRegionalism =(Map<String, Object>)basicInfo.get("permanentAddressRegionalism");

					//25
					colIndex ++;
					cell = row.createCell(colIndex);
					if(permanentAddressRegionalism != null){
						Object provinceCode = permanentAddressRegionalism.get("provinceCode");
						setCellValue(provinceCode,cell);
					}

					//26
					colIndex ++;
					cell = row.createCell(colIndex);
					if(permanentAddressRegionalism != null){
						Object cityCode = permanentAddressRegionalism.get("cityCode");
						setCellValue(cityCode,cell);
					}

					//27
					colIndex ++;
					cell = row.createCell(colIndex);
					if(permanentAddressRegionalism != null){
						Object countyCode = permanentAddressRegionalism.get("countyCode");
						setCellValue(countyCode,cell);
					}

					//28
					colIndex ++;
					cell = row.createCell(colIndex);
					Object permanentAddress = basicInfo.get("permanentAddress");
					setCellValue(permanentAddress,cell);

					//29
					colIndex ++;
					cell = row.createCell(colIndex);
					Object permanentAddressPhone = basicInfo.get("permanentAddressPhone");
					setCellValue(permanentAddressPhone,cell);

					//30
					colIndex ++;
					cell = row.createCell(colIndex);
					Object permanentAddressPostCode = basicInfo.get("permanentAddressPostCode");
					setCellValue(permanentAddressPostCode,cell);

					Map<String, Object> registeredAddressRegionalism =(Map<String, Object>)basicInfo.get("registeredAddressRegionalism");

					//31
					colIndex ++;
					cell = row.createCell(colIndex);
					if(registeredAddressRegionalism != null){
						Object provinceCode = registeredAddressRegionalism.get("provinceCode");
						setCellValue(provinceCode,cell);
					}

					//32
					colIndex ++;
					cell = row.createCell(colIndex);
					if(registeredAddressRegionalism != null){
						Object cityCode = registeredAddressRegionalism.get("cityCode");
						setCellValue(cityCode,cell);
					}

					//33
					colIndex ++;
					cell = row.createCell(colIndex);
					if(registeredAddressRegionalism != null){
						Object countyCode = registeredAddressRegionalism.get("countyCode");
						setCellValue(countyCode,cell);
					}

					//34
					colIndex ++;
					cell = row.createCell(colIndex);
					Object registeredAddress = basicInfo.get("registeredAddress");
					setCellValue(registeredAddress,cell);

					//35
					colIndex ++;
					cell = row.createCell(colIndex);
					Object registeredAddressPostCode = basicInfo.get("registeredAddressPostCode");
					setCellValue(registeredAddressPostCode,cell);

					//36
					colIndex ++;
					cell = row.createCell(colIndex);
					Object workUnitName = basicInfo.get("workUnitName");
					setCellValue(workUnitName,cell);

					Map<String, Object> workUnitRegionalism =(Map<String, Object>)basicInfo.get("workUnitRegionalism");

					//37
					colIndex ++;
					cell = row.createCell(colIndex);
					if(workUnitRegionalism != null){
						Object provinceCode = workUnitRegionalism.get("provinceCode");
						setCellValue(provinceCode,cell);
					}

					//38
					colIndex ++;
					cell = row.createCell(colIndex);
					if(workUnitRegionalism != null){
						Object cityCode = workUnitRegionalism.get("cityCode");
						setCellValue(cityCode,cell);
					}

					//39
					colIndex ++;
					cell = row.createCell(colIndex);
					if(workUnitRegionalism != null){
						Object countyCode = workUnitRegionalism.get("countyCode");
						setCellValue(countyCode,cell);
					}

					//40
					colIndex ++;
					cell = row.createCell(colIndex);
					Object workUnitAddress = basicInfo.get("workUnitAddress");
					setCellValue(workUnitAddress,cell);
					//[end]

					//[start] 41-60
					//41
					colIndex ++;
					cell = row.createCell(colIndex);
					Object workUnitPhone = basicInfo.get("workUnitPhone");
					setCellValue(workUnitPhone,cell);

					//42
					colIndex ++;
					cell = row.createCell(colIndex);
					Object workUnitPostCode = basicInfo.get("workUnitPostCode");
					setCellValue(workUnitPostCode,cell);

					//43
					colIndex ++;
					cell = row.createCell(colIndex);
					Object linkManName = basicInfo.get("linkManName");
					setCellValue(linkManName,cell);

					//44
					colIndex ++;
					cell = row.createCell(colIndex);
					Object linkManRelativeRelationCode = basicInfo.get("linkManRelativeRelationCode");
					setCellValue(linkManRelativeRelationCode,cell);

					Map<String, Object> linkManAddressRegionalism =(Map<String, Object>)basicInfo.get("linkManAddressRegionalism");

					//45
					colIndex ++;
					cell = row.createCell(colIndex);
					if(linkManAddressRegionalism != null){
						Object provinceCode = linkManAddressRegionalism.get("provinceCode");
						setCellValue(provinceCode,cell);
					}

					//46
					colIndex ++;
					cell = row.createCell(colIndex);
					if(linkManAddressRegionalism != null){
						Object cityCode = linkManAddressRegionalism.get("cityCode");
						setCellValue(cityCode,cell);
					}

					//47
					colIndex ++;
					cell = row.createCell(colIndex);
					if(linkManAddressRegionalism != null){
						Object countyCode = linkManAddressRegionalism.get("countyCode");
						setCellValue(countyCode,cell);
					}

					//48
					colIndex ++;
					cell = row.createCell(colIndex);
					Object linkManAddress = basicInfo.get("linkManAddress");
					setCellValue(linkManAddress,cell);

					//49
					colIndex ++;
					cell = row.createCell(colIndex);
					Object linkManPhone = basicInfo.get("linkManPhone");
					setCellValue(linkManPhone,cell);

					//50
					colIndex ++;
					cell = row.createCell(colIndex);
					Object inHospitalTypeCode = basicInfo.get("inHospitalTypeCode");
					setCellValue(inHospitalTypeCode,cell);

					//51
					colIndex ++;
					cell = row.createCell(colIndex);
					Object shiftToUnitName = basicInfo.get("shiftToUnitName");
					setCellValue(shiftToUnitName,cell);

					//52
					colIndex ++;
					cell = row.createCell(colIndex);
					Object inHospitalDateTimeObj = basicInfo.get("inHospitalDateTime");
					Date inHospitalDateTime = null;
					if(inHospitalDateTimeObj != null){
						inHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, (String)inHospitalDateTimeObj);
					}
					if(inHospitalDateTime != null){
						setCellValue(DateUtil.dateFormat("yyyyMMdd", inHospitalDateTime),cell);
					}


					//53
					colIndex ++;
					cell = row.createCell(colIndex);
					if(inHospitalDateTime != null){
						setCellValue(DateUtil.dateFormat("HH", inHospitalDateTime),cell);
					}

					//54
					colIndex ++;
					cell = row.createCell(colIndex);
					Object inDeptCode = basicInfo.get("inDeptCode");
					setCellValue(inDeptCode,cell);

					//55
					colIndex ++;
					cell = row.createCell(colIndex);
					Object inHospitalHouseName = basicInfo.get("inHospitalHouseName");
					setCellValue(inHospitalHouseName,cell);

					Map<String, Object> transferDeptInfo = (Map<String, Object>)jsonMap.get("transferDeptInfo");

					if(transferDeptInfo != null){
						List<Map<String, Object>> transferDeptRecords = (List<Map<String, Object>>)transferDeptInfo.get("transferDeptRecords");
						//56
						colIndex ++;
						cell = row.createCell(colIndex);
						if(transferDeptRecords.size() >= 1){
							Object transferInDeptCode = transferDeptRecords.get(0).get("inDeptCode");
							setCellValue(transferInDeptCode,cell);
						}
						//57
						colIndex ++;
						cell = row.createCell(colIndex);
						if(transferDeptRecords.size() >=2){
							Object transferInDeptCode = transferDeptRecords.get(1).get("inDeptCode");
							setCellValue(transferInDeptCode,cell);
						}
						//58
						colIndex ++;
						cell = row.createCell(colIndex);
						if(transferDeptRecords.size() >= 3){
							Object transferInDeptCode = transferDeptRecords.get(2).get("inDeptCode");
							setCellValue(transferInDeptCode,cell);
						}
					}else{
						//56
						colIndex ++;
						cell = row.createCell(colIndex);

						//57
						colIndex ++;
						cell = row.createCell(colIndex);

						//58
						colIndex ++;
						cell = row.createCell(colIndex);
					}


					//59
					colIndex ++;
					cell = row.createCell(colIndex);
					Object outHospitalDateTimeObj = basicInfo.get("outHospitalDateTime");
					Date outHospitalDateTime = null;
					if(outHospitalDateTimeObj != null){
						outHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, (String)outHospitalDateTimeObj);
					}
					if(outHospitalDateTime != null){
						setCellValue(DateUtil.dateFormat("yyyyMMdd", outHospitalDateTime),cell);
					}

					//60
					colIndex ++;
					cell = row.createCell(colIndex);
					if(outHospitalDateTime != null){
						setCellValue(DateUtil.dateFormat("HH", outHospitalDateTime),cell);
					}
					//[end]


					//[start] 61-113
					//61
					colIndex ++;
					cell = row.createCell(colIndex);
					Object outDeptCode = basicInfo.get("outDeptCode");
					setCellValue(outDeptCode,cell);

					//62
					colIndex ++;
					cell = row.createCell(colIndex);
					Object outHospitalHouseName = basicInfo.get("outHospitalHouseName");
					setCellValue(outHospitalHouseName,cell);

					//63
					colIndex ++;
					cell = row.createCell(colIndex);
					Object inHospitalDayNumber = basicInfo.get("inHospitalDayNumber");
					setCellValue(inHospitalDayNumber,cell);

					Map<String, Object> diseaseDiagInfo = (Map<String, Object>)jsonMap.get("hqmsDiseaseDiagInfo");

					Map<String, Object> outpatientDiagRecord = (Map<String, Object>)diseaseDiagInfo.get("outpatientDiagRecord");

					//64
					colIndex ++;
					cell = row.createCell(colIndex);
					if(outpatientDiagRecord != null){
						Object diseaseDiagName = outpatientDiagRecord.get("diseaseDiagName");
						setCellValue(diseaseDiagName,cell);
					}

					//65
					colIndex ++;
					cell = row.createCell(colIndex);
					if(outpatientDiagRecord != null){
						Object diseaseDiagCode = outpatientDiagRecord.get("diseaseDiagCode");
						setCellValue(diseaseDiagCode,cell);
					}

					Map<String, Object> mainDiagRecord = (Map<String, Object>)diseaseDiagInfo.get("mainDiagRecord");

					//66
					colIndex ++;
					cell = row.createCell(colIndex);
					if(mainDiagRecord != null){
						Object diseaseDiagName = mainDiagRecord.get("diseaseDiagName");
						setCellValue(diseaseDiagName,cell);
					}

					//67
					colIndex ++;
					cell = row.createCell(colIndex);
					if(mainDiagRecord != null){
						Object diseaseDiagCode = mainDiagRecord.get("diseaseDiagCode");
						setCellValue(diseaseDiagCode,cell);
					}

					//68
					colIndex ++;
					cell = row.createCell(colIndex);
					if(mainDiagRecord != null){
						Object inHospitalDiseaseStateCode = mainDiagRecord.get("inHospitalDiseaseStateCode");
						setCellValue(inHospitalDiseaseStateCode,cell);
					}

					List<Map<String, Object>> diseaseDiagRecords = (List<Map<String, Object>>)diseaseDiagInfo.get("diseaseDiagRecords");



					//69-113
					for(int otherIndex = 0;otherIndex<15; otherIndex++){
						Map<String, Object> otherDiagRecord = null;
						if(diseaseDiagRecords.size() > otherIndex){
							otherDiagRecord = diseaseDiagRecords.get(otherIndex);
						}
						//69
						colIndex ++;
						cell = row.createCell(colIndex);
						if(otherDiagRecord != null){
							Object diseaseDiagName = otherDiagRecord.get("diseaseDiagName");
							setCellValue(diseaseDiagName,cell);
						}

						//70
						colIndex ++;
						cell = row.createCell(colIndex);
						if(otherDiagRecord != null){
							Object diseaseDiagCode = otherDiagRecord.get("diseaseDiagCode");
							setCellValue(diseaseDiagCode,cell);
						}

						//71
						colIndex ++;
						cell = row.createCell(colIndex);
						if(otherDiagRecord != null){
							Object inHospitalDiseaseStateCode = otherDiagRecord.get("inHospitalDiseaseStateCode");
							setCellValue(inHospitalDiseaseStateCode,cell);
						}
					}

					//[end]

					//[start] 114-129
					List<Map<String, Object>> damageAndVenenationDiagRecords = (List<Map<String, Object>>)diseaseDiagInfo.get("damageAndVenenationDiagRecords");

					if(damageAndVenenationDiagRecords.size() > 0){
						Map<String, Object> damageAndVenenationDiagRecord = damageAndVenenationDiagRecords.get(0);
						//114
						colIndex ++;
						cell = row.createCell(colIndex);
						if(damageAndVenenationDiagRecord != null){
							Object diseaseDiagName = damageAndVenenationDiagRecord.get("diseaseDiagName");
							setCellValue(diseaseDiagName,cell);
						}

						//115
						colIndex ++;
						cell = row.createCell(colIndex);
						if(damageAndVenenationDiagRecord != null){
							Object diseaseDiagCode = damageAndVenenationDiagRecord.get("diseaseDiagCode");
							setCellValue(diseaseDiagCode,cell);
						}

					}else{
						//114
						colIndex ++;
						cell = row.createCell(colIndex);
						//115
						colIndex ++;
						cell = row.createCell(colIndex);
					}


					List<Map<String, Object>> pathologyDiagRecords = (List<Map<String, Object>>)diseaseDiagInfo.get("pathologyDiagRecords");
					if(pathologyDiagRecords.size() > 0){
						Map<String, Object> pathologyDiagRecord = pathologyDiagRecords.get(0);
						//116
						colIndex ++;
						cell = row.createCell(colIndex);
						if(pathologyDiagRecord != null){
							Object diseaseDiagName = pathologyDiagRecord.get("diseaseDiagName");
							setCellValue(diseaseDiagName,cell);
						}

						//117
						colIndex ++;
						cell = row.createCell(colIndex);
						if(pathologyDiagRecord != null){
							Object diseaseDiagCode = pathologyDiagRecord.get("diseaseDiagCode");
							setCellValue(diseaseDiagCode,cell);
						}

						//118
						colIndex ++;
						cell = row.createCell(colIndex);
						if(pathologyDiagRecord != null){
							Object pathologyNumber = pathologyDiagRecord.get("pathologyNumber");
							setCellValue(pathologyNumber,cell);
						}

					}


					//119
					colIndex++;
					cell = row.createCell(colIndex);

					//120
					colIndex++;
					cell = row.createCell(colIndex);
					if(cureInfo != null){
						Object malignantTumorHighestDiagBasisCode = cureInfo.get("malignantTumorHighestDiagBasisCode");
						setCellValue(malignantTumorHighestDiagBasisCode,cell);
					}

					//121
					colIndex ++;
					cell = row.createCell(colIndex);


					//122
					colIndex ++;
					cell = row.createCell(colIndex);

					//123
					colIndex++;
					cell = row.createCell(colIndex);
					Object autopsyCode = basicInfo.get("autopsyCode");
					setCellValue(autopsyCode,cell);

					//124
					colIndex++;
					cell = row.createCell(colIndex);
					if(cureInfo != null){
						Object bloodTypeCode = cureInfo.get("bloodTypeCode");
						setCellValue(bloodTypeCode,cell);
					}

					Map<String, Object> nurseInfo = (Map<String, Object>)jsonMap.get("nurseInfo");

					//125
					colIndex++;
					cell = row.createCell(colIndex);
					if(nurseInfo != null){
						Object specialNurseDayNumber = nurseInfo.get("specialNurseDayNumber");
						setCellValue(specialNurseDayNumber,cell);
					}

					//126
					colIndex++;
					cell = row.createCell(colIndex);
					if(nurseInfo != null){
						Object firstLevelNurseDayNumber = nurseInfo.get("firstLevelNurseDayNumber");
						setCellValue(firstLevelNurseDayNumber,cell);
					}

					//127
					colIndex++;
					cell = row.createCell(colIndex);
					if(nurseInfo != null){
						Object secondLevelNurseDayNumber = nurseInfo.get("secondLevelNurseDayNumber");
						setCellValue(secondLevelNurseDayNumber,cell);
					}

					//128
					colIndex++;
					cell = row.createCell(colIndex);
					if(nurseInfo != null){
						Object threeLevelNurseDayNumber = nurseInfo.get("threeLevelNurseDayNumber");
						setCellValue(threeLevelNurseDayNumber,cell);
					}

					//129
					colIndex++;
					cell = row.createCell(colIndex);
					if(cureInfo != null){
						Object rhBloodTypeCode = cureInfo.get("rhBloodTypeCode");
						setCellValue(rhBloodTypeCode,cell);
					}
					//[end]

					//[start] 130-142
					if(cureInfo != null){
						List<Map<String, Object>> cureWorkers = (List<Map<String, Object>>)cureInfo.get("cureWorkers");
						//130
						String workerA1001Name=null;
						//131
						String workerA1003Name=null;
						//132
						String workerA2001Name=null;
						//133
						String workerA2003Name=null;
						//134
						String workerA2005Name=null;
						//135
						String workerA3001Name=null;
						//136
						String workerA2006Name=null;
						//137
						String workerA2008Name=null;
						//138
						String workerA4001Name=null;
						//140
						String workerA2009Name=null;
						//141
						String workerA3003Name=null;
						for (Map<String, Object> cureWorker : cureWorkers) {
							String professionTitleCode = (String)cureWorker.get("professionTitleCode");
							if("A1001".equals(professionTitleCode)){
								workerA1001Name = (String)cureWorker.get("medicalWorkerName");
							}else if("A1003".equals(professionTitleCode)){
								workerA1003Name = (String)cureWorker.get("medicalWorkerName");
							}else if("A2001".equals(professionTitleCode)){
								workerA2001Name = (String)cureWorker.get("medicalWorkerName");
							}else if("A2003".equals(professionTitleCode)){
								workerA2003Name = (String)cureWorker.get("medicalWorkerName");
							}else if("A2005".equals(professionTitleCode)){
								workerA2005Name = (String)cureWorker.get("medicalWorkerName");
							}else if("A3001".equals(professionTitleCode)){
								workerA3001Name = (String)cureWorker.get("medicalWorkerName");
							}else if("2006".equals(professionTitleCode)){
								workerA2006Name = (String)cureWorker.get("medicalWorkerName");
							}else if("A2008".equals(professionTitleCode)){
								workerA2008Name = (String)cureWorker.get("medicalWorkerName");
							}else if("A4001".equals(professionTitleCode)){
								workerA4001Name = (String)cureWorker.get("medicalWorkerName");
							}else if("A2009".equals(professionTitleCode)){
								workerA2009Name = (String)cureWorker.get("medicalWorkerName");
							}else if("A3003".equals(professionTitleCode)){
								workerA3003Name = (String)cureWorker.get("medicalWorkerName");
							}

						}

						cell = row.createCell(129);
						setCellValue(workerA1001Name,cell);
						cell = row.createCell(130);
						setCellValue(workerA1003Name,cell);
						cell = row.createCell(131);
						setCellValue(workerA2001Name,cell);
						cell = row.createCell(132);
						setCellValue(workerA2003Name,cell);
						cell = row.createCell(133);
						setCellValue(workerA2005Name,cell);
						cell = row.createCell(134);
						setCellValue(workerA3001Name,cell);
						cell = row.createCell(135);
						setCellValue(workerA2006Name,cell);
						cell = row.createCell(136);
						setCellValue(workerA2008Name,cell);
						cell = row.createCell(137);
						setCellValue(workerA4001Name,cell);
						cell = row.createCell(139);
						setCellValue(workerA2009Name,cell);
						cell = row.createCell(140);
						setCellValue(workerA3003Name,cell);
						Object medicalRecordQualityCode = cureInfo.get("medicalRecordQualityCode");
						cell = row.createCell(138);
						setCellValue(medicalRecordQualityCode,cell);

						cell = row.createCell(141);
						Object qualityControlDateTimeObj = cureInfo.get("qualityControlDateTime");

						Date qualityControlDateTime = null;
						if(qualityControlDateTimeObj != null){
							qualityControlDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, (String)qualityControlDateTimeObj);
						}
						if(qualityControlDateTime != null){
							setCellValue(DateUtil.dateFormat("yyyyMMdd", qualityControlDateTime),cell);
						}
					}
					colIndex =141;
					//[end]

					//[start] 142-238
					Map<String, Object> operateInfo = (Map<String, Object>)jsonMap.get("hqmsOperateInfo");
					if(operateInfo != null){
						List<Map<String, Object>> operateRecords = (List<Map<String, Object>>)operateInfo.get("operateRecords");
						for (Map<String, Object> operateRecord : operateRecords) {
							if(colIndex >=237){
								break;
							}
							colIndex ++;
							Object operateCode = operateRecord.get("operateCode");
							cell = row.createCell(colIndex);
							setCellValue(operateCode,cell);

							colIndex ++;
							Object operateStartDateObj = operateRecord.get("operateStartDate");
							cell = row.createCell(colIndex);
							Date operateStartDate = null;
							if(operateStartDateObj != null){
								operateStartDate = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, (String)operateStartDateObj);
							}
							if(operateStartDate != null){
								setCellValue(DateUtil.dateFormat("yyyyMMdd", operateStartDate),cell);
							}

							colIndex ++;
							Object opsLevelCode = operateRecord.get("opsLevelCode");
							cell = row.createCell(colIndex);
							setCellValue(opsLevelCode,cell);

							colIndex ++;
							Object patientSourceCode = operateRecord.get("patientSourceCode");
							cell = row.createCell(colIndex);
							setCellValue(patientSourceCode,cell);


							colIndex ++;
							Object operateName = operateRecord.get("operateName");
							cell = row.createCell(colIndex);
							setCellValue(operateName,cell);


							List<Map<String, Object>> operateWorkers = (List<Map<String, Object>>)operateRecord.get("operateWorkers");
							String workerA5001Name=null;
							String workerA5002Name=null;
							String workerA5003Name=null;
							String workerA5004Name=null;
							for (Map<String, Object> operateWorker : operateWorkers) {
								String professionTitleCode = (String)operateWorker.get("professionTitleCode");
								if("A5001".equalsIgnoreCase(professionTitleCode)){
									workerA5001Name = (String)operateWorker.get("medicalWorkerName");
								}else if("A5002".equalsIgnoreCase(professionTitleCode)){
									workerA5002Name = (String)operateWorker.get("medicalWorkerName");
								}else if("A5003".equalsIgnoreCase(professionTitleCode)){
									workerA5003Name = (String)operateWorker.get("medicalWorkerName");
								}else if("A5004".equalsIgnoreCase(professionTitleCode)){
									workerA5004Name = (String)operateWorker.get("medicalWorkerName");
								}
							}
							colIndex ++;
							cell = row.createCell(colIndex);
							setCellValue(workerA5001Name,cell);

							colIndex ++;
							cell = row.createCell(colIndex);
							setCellValue(workerA5003Name,cell);
							colIndex ++;
							cell = row.createCell(colIndex);
							setCellValue(workerA5004Name,cell);

							colIndex ++;
							Object incisionLevelCode = operateRecord.get("incisionLevelCode");
							cell = row.createCell(colIndex);
							setCellValue(incisionLevelCode,cell);

							colIndex ++;
							Object cicatrizeTypeCode = operateRecord.get("cicatrizeTypeCode");
							cell = row.createCell(colIndex);
							setCellValue(cicatrizeTypeCode,cell);

							colIndex ++;
							Object anaesthesiaTypeCode = operateRecord.get("anaesthesiaTypeCode");
							cell = row.createCell(colIndex);
							setCellValue(anaesthesiaTypeCode,cell);

							colIndex ++;
							cell = row.createCell(colIndex);
							setCellValue(workerA5002Name,cell);

						}
					}

					colIndex = 237;
					//[end]
					cell = row.createCell(238);
					cell = row.createCell(239);
					cell = row.createCell(240);
					Object outHospitalTypeCode = basicInfo.get("outHospitalTypeCode");

					cell = row.createCell(241);

					setCellValue(outHospitalTypeCode,cell);

					Object receiveUnitName = basicInfo.get("receiveUnitName");


					if(outHospitalTypeCode!=null){
						if("2".equalsIgnoreCase((String)outHospitalTypeCode)){
							cell = row.createCell(242);
							setCellValue(receiveUnitName,cell);
						}else if("3".equalsIgnoreCase((String)outHospitalTypeCode)){
							cell = row.createCell(243);
							setCellValue(receiveUnitName,cell);
						}
					}

					if(cureInfo != null){
						Object rehospitalAimOf31Code = cureInfo.get("rehospitalAimOf31Code");
						cell = row.createCell(244);
						setCellValue(rehospitalAimOf31Code,cell);
						Object rehospitalAimOf31Description = cureInfo.get("rehospitalAimOf31Description");
						cell = row.createCell(245);
						setCellValue(rehospitalAimOf31Description,cell);

						Object dayOfBeforeInHospitalComa = cureInfo.get("dayOfBeforeInHospitalComa");
						cell = row.createCell(246);
						setCellValue(dayOfBeforeInHospitalComa,cell);

						Object hourOfBeforeInHospitalComa = cureInfo.get("hourOfBeforeInHospitalComa");
						cell = row.createCell(247);
						setCellValue(hourOfBeforeInHospitalComa,cell);

						Object minuteOfBeforeInHospitalComa = cureInfo.get("minuteOfBeforeInHospitalComa");
						cell = row.createCell(248);
						setCellValue(minuteOfBeforeInHospitalComa,cell);

						Object dayOfAfterInHospitalComa = cureInfo.get("dayOfAfterInHospitalComa");
						cell = row.createCell(249);
						setCellValue(dayOfAfterInHospitalComa,cell);

						Object hourOfAfterInHospitalComa = cureInfo.get("hourOfAfterInHospitalComa");
						cell = row.createCell(250);
						setCellValue(hourOfAfterInHospitalComa,cell);

						Object minuteOfAfterInHospitalComa = cureInfo.get("minuteOfAfterInHospitalComa");
						cell = row.createCell(251);
						setCellValue(minuteOfAfterInHospitalComa,cell);
					}


					/*for(int colIndex = 0; colIndex < keys.size(); colIndex++){
						cell = row.createCell(colIndex);
						Object value = data.get(keys.get(colIndex));
						if(value instanceof String){
							cell.setCellValue((String)value);
						}else if(value instanceof Integer){
							cell.setCellValue((Integer)value);
						}else if(value instanceof Date){
							cell.setCellValue(DateUtil.dateFormat((Date)value));
						}else{
							cell.setCellValue(value.toString());
						}

					}*/
				}

				i++;
			}

			workbook.write(out);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}


	public static void exportExcelOfPageIndex1(OutputStream out,List<Map<String, Object>> datas) {

		try {

			// 创建一个工作薄
			HSSFWorkbook workbook = new HSSFWorkbook();
			// 创建一个sheet页
			HSSFSheet sheet = workbook.createSheet();

			HSSFRow row = null;
			HSSFCell cell = null;

			// 创建第一行，生成表格的表头行
			row = sheet.createRow(0);// 第一行
			String[] headers =
				{ "患者姓名","患者性别代码","患者性别名称","出生日期",
				"年龄（年）", "年龄（月）","患者婚姻代码","患者婚姻名称",
				"职业代码","职业名称","出生地","出生地邮编","联系电话",
				"国籍代码","国籍名称","民族代码","民族名称","籍贯",
				"户口地址","户口邮编","证件类型代码","证件类型名称","证件号码",
				"病案号","住院次数"};
			for (int i = 0; i < headers.length; i++) {
				cell = row.createCell(i);// 从第一列开始
				cell.setCellValue(headers[i]);
			}
			int i = 0;
			for (Map<String, Object> data : datas) {
				Map<String, Object> jsonMap = (Map<String, Object>)data.get("jsonMap");
				row = sheet.createRow(1 + i);// 从第二行去写数据
				if(jsonMap != null){
					Map<String, Object> basicInfo = (Map<String, Object>)jsonMap.get("basicInfo");
					int colIndex = 0;
					//1
					cell = row.createCell(colIndex);
					Object patientName = basicInfo.get("patientName");
					setCellValue(patientName,cell);
					colIndex ++;
					//2
					cell = row.createCell(colIndex);
					Object sexCode = basicInfo.get("sexCode");
					setCellValue(sexCode,cell);
					colIndex ++;
					//3
					cell = row.createCell(colIndex);
					Object sexName = basicInfo.get("sexName");
					setCellValue(sexName,cell);
					colIndex ++;
					//4
					cell = row.createCell(colIndex);
					Object birthday = basicInfo.get("birthday");
					setCellValue(birthday,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object yearOfAge = basicInfo.get("yearOfAge");
					setCellValue(yearOfAge,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object monthOfAge = basicInfo.get("monthOfAge");
					setCellValue(monthOfAge,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object marriageCode = basicInfo.get("marriageCode");
					setCellValue(marriageCode,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object marriageName = basicInfo.get("marriageName");
					setCellValue(marriageName,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object professionCode = basicInfo.get("professionCode");
					setCellValue(professionCode,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object professionName = basicInfo.get("professionName");
					setCellValue(professionName,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object birthAddress = basicInfo.get("birthAddress");
					setCellValue(birthAddress,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object birthAddressPostCode = basicInfo.get("birthAddressPostCode");
					setCellValue(birthAddressPostCode,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object telePhone = basicInfo.get("telePhone");
					setCellValue(telePhone,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object nationalityCode = basicInfo.get("nationalityCode");
					setCellValue(nationalityCode,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object nationalityName = basicInfo.get("nationalityName");
					setCellValue(nationalityName,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object nationCode = basicInfo.get("nationCode");
					setCellValue(nationCode,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object nationName = basicInfo.get("nationName");
					setCellValue(nationName,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object nativePlace = basicInfo.get("nativePlace");
					setCellValue(nativePlace,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object registeredAddress = basicInfo.get("registeredAddress");
					setCellValue(registeredAddress,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object registeredAddressPostCode = basicInfo.get("registeredAddressPostCode");
					setCellValue(registeredAddressPostCode,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object documentTypeCode = basicInfo.get("documentTypeCode");
					setCellValue(documentTypeCode,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object documentTypeName = basicInfo.get("documentTypeName");
					setCellValue(documentTypeName,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object idNumber = basicInfo.get("idNumber");
					setCellValue(idNumber,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object mrId = basicInfo.get("mrId");
					setCellValue(mrId,cell);
					colIndex ++;
					cell = row.createCell(colIndex);
					Object visitNumber = basicInfo.get("visitNumber");
					setCellValue(visitNumber,cell);
					/*for(int colIndex = 0; colIndex < keys.size(); colIndex++){
						cell = row.createCell(colIndex);
						Object value = data.get(keys.get(colIndex));
						if(value instanceof String){
							cell.setCellValue((String)value);
						}else if(value instanceof Integer){
							cell.setCellValue((Integer)value);
						}else if(value instanceof Date){
							cell.setCellValue(DateUtil.dateFormat((Date)value));
						}else{
							cell.setCellValue(value.toString());
						}

					}*/
				}

				i++;
			}

			workbook.write(out);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private static void setCellValue(Object obj,HSSFCell cell){
		if(obj instanceof String){
			cell.setCellValue((String)obj);
		}else if(obj instanceof Integer){
			cell.setCellValue((Integer)obj);
		}else if(obj instanceof Date){
			cell.setCellValue(DateUtil.dateFormat((Date)obj));
		}else if(obj instanceof BigDecimal){
			cell.setCellValue(((BigDecimal)obj).floatValue());
		}else if(obj instanceof Long){
			cell.setCellValue(((Long)obj).intValue());
		}
	}

	private static void setCellValue(Object obj,XSSFCell cell){
		if(obj instanceof String){
			cell.setCellValue((String)obj);
		}else if(obj instanceof Integer){
			cell.setCellValue((Integer)obj);
		}else if(obj instanceof Date){
			cell.setCellValue(DateUtil.dateFormat((Date)obj));
		}else if(obj instanceof BigDecimal){
			cell.setCellValue(((BigDecimal)obj).floatValue());
		}else if(obj instanceof Long){
			cell.setCellValue(((Long)obj).intValue());
		}
	}

	/**
	 * 导出excel数据
	 *
	 * @param filePath
	 * @return
	 */
	public static void exportExcel(OutputStream out, String title, String[] header, List<Map<String, Object>> mapList) {
		// 创建一个工作薄
		HSSFWorkbook workbook = null;
		try {

			// 创建一个工作薄
			workbook = new HSSFWorkbook();
			// 创建一个sheet页
			HSSFSheet sheet = workbook.createSheet();
			// 设置sheet页的列宽
			sheet.setDefaultColumnWidth(20);

			// 设置标题样式
			HSSFCellStyle titleStyle = workbook.createCellStyle();
			// 设置字体居中显示
			//titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			// 设置标题字体
			HSSFFont titleFont = workbook.createFont();
			titleFont.setFontHeightInPoints((short) 25);
			titleStyle.setFont(titleFont);

			// 产生标题
			HSSFRow row = sheet.createRow(0);
			HSSFCell cell = row.createCell(0);
			cell.setCellStyle(titleStyle);
			cell.setCellValue(title);
			// 合并单元格
			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, header.length - 1));

			// 表头样式
			HSSFCellStyle headStyle = workbook.createCellStyle();
			//headStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
			// 设置填充模式
			//headStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

			// 设置字体居中
			//headStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			//headStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			//headStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			//headStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
			//headStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
			// 设置字体样式
			HSSFFont headFont = workbook.createFont();
			//headFont.setColor(HSSFColor.LIGHT_ORANGE.index);
			//headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 设置字体粗细
			headFont.setFontHeightInPoints((short) 16);
			headStyle.setFont(headFont);
			// 创建第二行，生成表格的表头行
			row = sheet.createRow(1);// 第二行
			for (int i = 0; i < header.length; i++) {
				cell = row.createCell(i);// 从第一列开始
				cell.setCellStyle(headStyle);// 设置列的样式
				cell.setCellValue(header[i]);
			}
			int i = 0;
			for (Map<String, Object> cellMap : mapList) {
				row = sheet.createRow(2 + i);// 从第三行去写数据
				int j = 0;
				for (Map.Entry<String, Object> entry : cellMap.entrySet()) {
					cell = row.createCell(j);
					Object obj = entry.getValue();
					if (obj instanceof Integer) {
						cell.setCellValue((Integer) entry.getValue());
					}
					if (obj instanceof Date) {
						cell.setCellValue(DateUtil.dateFormat((Date)entry.getValue()));
					}
					if (obj instanceof String) {
						cell.setCellValue((String) entry.getValue());
					}
					if (obj instanceof Double) {
						cell.setCellValue((Double) entry.getValue());
					}
					if (obj instanceof Float) {
						cell.setCellValue((Float) entry.getValue());
					}
					if (obj instanceof Long) {
						cell.setCellValue((Long) entry.getValue());
					}

					j++;
				}
				i++;
			}

			workbook.write(out);
			out.flush();
			out.close();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
